package com.example.emos.api.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * @author: LC
 * @date 2022/4/22 13:41
 * @ClassName: EmailTask
 */
@Component
public class EmailTask implements Serializable {
    @Value("${spring.mail.username")
    private String mailbox;

    @Autowired
    private JavaMailSender javaMailSender;

    @Async
    public void sendAsync(SimpleMailMessage simpleMailMessage) {
        simpleMailMessage.setFrom(this.mailbox);
        this.javaMailSender.send(simpleMailMessage);
    }
}
